package ogs.lib.mina.core.filterchain
{
	import flash.utils.ByteArray;
	import flash.utils.Endian;
	
	import mx.charts.chartClasses.InstanceCache;
	
	import ogs.lib.mina.core.service.IoConnector;

	public class HeadFilter extends IoFilterAdapter
	{
		private var connector:IoConnector;
		
		public function HeadFilter(connector:IoConnector)
		{
			super();
			this.connector = connector;
		}
		
		override public function filterWrite(nextFilter:NextFilter, message:Object):void
		{
			if (message is ByteArray)
			{
				connector.sendRawData(ByteArray(message));
			} else
			{
				var data:ByteArray = new ByteArray();
				data.endian = Endian.LITTLE_ENDIAN;
				data.writeObject(message);
				
				connector.sendRawData(data);
			}
		}
		
		override public function filterClose(nextFilter:NextFilter):void
		{
			connector.closeSocketDirectly();
		}
	}
}